package com.hsu.yupao.exception;

import com.hsu.yupao.common.ErrorCode;
import lombok.Getter;

/**
 * 自定义异常类
 * @ClassName: BusinessException
 * @author Hsu琛君珩
 * @date 2024-03-21
 * @apiNote
 * @Version: v1.0
 */
@Getter
public class BusinessException extends RuntimeException{
    //异常中的属性不需要 setter
    //这里就相当于给原来的 RuntimeException 扩充了这两个属性
    private final int code;
    private final String description;

    //并且创建了几个构造函数，让他能够使用 ErrorCode
    public BusinessException(String message, int code, String description) {
        super(message);
        this.code = code;
        this.description = description;
    }

    public BusinessException(ErrorCode errorCode) {
        super(errorCode.getMessage());
        this.code = errorCode.getCode();
        this.description = errorCode.getDescription();
    }

    public BusinessException(ErrorCode errorCode, String description) {
        super(errorCode.getMessage());
        this.code = errorCode.getCode();
        this.description = description;
    }
}
